package com.woniu.liuzhougov.relatedinformation.controller.impl;

import com.woniu.liuzhougov.businessproject.pojo.BusinessProject;
import com.woniu.liuzhougov.businessproject.vo.BusinessProjectUploadVO;
import com.woniu.liuzhougov.businessproject.vo.Result;
import com.woniu.liuzhougov.fileManage.constant.SysConstant;
import com.woniu.liuzhougov.fileManage.pojo.FileData;
import com.woniu.liuzhougov.fileManage.service.FileService;
import com.woniu.liuzhougov.relatedinformation.controller.AbstractRelatedInformationController;
import com.woniu.liuzhougov.relatedinformation.controller.RelatedInformationController;
import com.woniu.liuzhougov.relatedinformation.pojo.City;
import com.woniu.liuzhougov.relatedinformation.pojo.RelatedInformation;
import com.woniu.liuzhougov.relatedinformation.service.RelatedInformationService;
import com.woniu.liuzhougov.relatedinformation.service.impl.CityServiceImpl;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.io.File;
import java.io.IOException;
import java.util.List;
import java.util.UUID;

/**
 * @Description: desc
 * @author: Chris
 * @createDate: 2019/4/24 0024
 * @version: 1.0
 */
@Controller
@RequestMapping("/city")
public class CityController extends AbstractRelatedInformationController<City> implements RelatedInformationController<City> {

    @Resource(name = "cityService")
    private RelatedInformationService cityService;

    @Autowired
    private FileService fileService;

    @Override
    @RequestMapping("/list")
    @ResponseBody
    @RequiresPermissions(value = "city_listCitys")
    public Result list() {
        return new Result(cityService.selectList());
    }

    @Override
    @RequestMapping("/search")
    @ResponseBody
    @RequiresPermissions(value = "city_searchCity")
    public Result search(String name) {
        return parentSearch(cityService,name);
    }

    @Override
    @RequestMapping("/delete")
    @ResponseBody
    @RequiresPermissions(value = "city_deleteCity")
    public Result delete(Integer[] deletelist) {
        return parentDelete(cityService,deletelist);
    }

    @Override
    @RequestMapping("/add")
    @ResponseBody
    @RequiresPermissions(value = "city_addCity")
    public Result add(City city) {
        return parentAdd(cityService,city);
    }

    @Override
    @RequestMapping("/update")
    @ResponseBody
    @RequiresPermissions(value = "city_updateCity")
    public Result update(City city) {
        return parentUpdate(cityService,city);
    }

    @Override
    @RequestMapping("/initForm")
    @ResponseBody
    @RequiresPermissions(value = "city_updateCity")
    public Result initForm(Integer id) {
        return parentInitForm(cityService,id);
    }

    /**
     * 文件上传
     * @param file
     * @param request
     * @return
     * @throws IOException
     * @throws IllegalStateException
     */
    @RequestMapping("/upload")
    @ResponseBody
    @RequiresPermissions(value = "file_upload")
    public com.woniu.liuzhougov.common.utils.Result upload(MultipartFile file, HttpServletRequest request) throws IOException,IllegalStateException {
        return parentUpload(cityService,file,request);
    }

    /**
     * 文件保存到数据库
     * @param fileData
     * @return
     */
    @RequestMapping("/addFile")
    @ResponseBody
    @RequiresPermissions(value = "file_upload")
    public com.woniu.liuzhougov.common.utils.Result addFile(RelatedInformation fileData){
        return parentAddFile(fileData);
    }
}

